package com.maxmlr.music.song.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.maxmlr.music.common.base.BaseController;
import com.maxmlr.music.common.bean.ResultBean;
import com.maxmlr.music.common.bean.ResultPageBean;
import com.maxmlr.music.common.param.PageParam;
import com.maxmlr.music.song.entity.Special;
import com.maxmlr.music.song.param.SpecialInfoParam;
import com.maxmlr.music.song.service.SpecialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.Arrays;

/**
 * @author max
 * @version 1.0
 * @ClassName SpecialController
 * @Description 专辑记录表 控制器
 * @Copyright Copyright (c) 2020: www.maxmlr.com.
 * @since 2020-06-07
 */
@Slf4j
@RestController
@Api(value = "/song/special", tags = "Special 控制器")
@RequestMapping("/song/special")
public class SpecialController extends BaseController<SpecialService, Special> {

    @Autowired
    public SpecialService service;


    /**
     * @Description 获取专辑信息
     * @author max
     * @since 2019-05-11
     */
    @GetMapping("/list")
    @ApiOperation(value = "/list", notes = "获取专辑分页列表")
    public ResultPageBean<SpecialInfoParam> listSpecialInfo(PageParam pageParam) {
        Page<SpecialInfoParam> page = getPage(pageParam);
        service.listSpecialInfo(page);
        return ResultPageBean.ok(page);
    }

    /**
     * 保存
     *
     * @param special
     * @return ResultBean<Boolean>
     */
    @PostMapping
    @RequiresPermissions("song:special:add" )
    public ResultBean<Boolean> save(SpecialInfoParam param) {
        return ResultBean.ok(service.saveParam(param));
    }

    /**
     * 修改
     *
     * @param special
     * @return ResultBean<Boolean>
     */
    @PutMapping
    @RequiresPermissions("song:special:edit" )
    public ResultBean<Boolean> update(SpecialInfoParam param) {
        return ResultBean.ok(service.updateParamById(param));
    }

    /**
     * 删除
     *
     * @param id
     * @return ResultBean<Boolean>
     */
    @DeleteMapping("/remove/{id}" )
    @RequiresPermissions("song:special:remove" )
    public ResultBean<Boolean> remove(@PathVariable("id" ) Serializable id) {
        return ResultBean.ok(service.removeById(id));
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return ResultBean<Boolean>
     */
    @DeleteMapping("/batch-remove")
    @RequiresPermissions("song:special:batch-remove")
    public ResultBean<Boolean> batchRemove(@RequestParam("ids[]") Serializable[] ids){
        return ResultBean.ok(service.removeByIds(Arrays.asList(ids)));
    }

}
